package com.nulldev.util.web.flexibleKit.scfk.protocols;

import java.util.Map;

import com.nulldev.util.data.Arrays.maps.FastMaps;
import com.nulldev.util.web.flexibleKit.scfk.protocols.gopher.GopherRequest;
import com.nulldev.util.web.flexibleKit.scfk.protocols.http1.Http1Request;

public class ProtocolManager {

	private static final Map<String, ProtocolRequest> PROTOCOLS;
	static {
		PROTOCOLS = FastMaps.map();
		if (PROTOCOLS.isEmpty()) {
			PROTOCOLS.put("http1", Http1Request.INSTANCE);
			PROTOCOLS.put("https1", Http1Request.INSTANCE);
			PROTOCOLS.put("gopher", GopherRequest.INSTANCE);
		}
	}

	public static boolean supportsProtocol(final String prot) {
		return PROTOCOLS.containsKey(prot);
	}

	public static ProtocolRequest requestFor(final PreferredProtocol prot) {
		switch (prot) {
			case HTTP_0_9:
			case HTTP_1_0:
			case HTTP_1_1:
				return PROTOCOLS.get("http1");
			default:
				return null;
		}
	}
}
